package cn.xmoit.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fangyy
 */
@RestController
public class IndexController {

	@RequestMapping({ "", "/" })
	public String welcome() {
		return "Welcome to the home page!";
	}

	@RequestMapping("/hello")
	public String hello() {
		return "Hello World!";
	}

	@PreAuthorize("hasRole('USER')")
	@RequestMapping("/user/info")
	public String userInfo() {
		return "User Info";
	}

	@PreAuthorize("hasRole('ADMIN')")
	@GetMapping("/admin/info")
	public String adminInfo() {
		return "Admin Info";
	}

	@GetMapping("/api/info")
	public String apiInfo() {
		return "Accessing API";
	}

}
